/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class FindElements
{
public:
    FindElements(TreeNode *root)
    {
        function<void(TreeNode *, int)> dfs = [&](TreeNode *t, int val)
        {
            this->elements.insert(val);
            if (t->left != nullptr)
            {
                dfs(t->left, 2 * val + 1);
            }
            if (t->right != nullptr)
            {
                dfs(t->right, 2 * val + 2);
            }
        };
        dfs(root, 0);
    }

    bool find(int target)
    {
        return this->elements.count(target);
    }

    unordered_set<int> elements;
};

/**
 * Your FindElements object will be instantiated and called as such:
 * FindElements* obj = new FindElements(root);
 * bool param_1 = obj->find(target);
 */